<?php
namespace App\Http\Controllers\Api\Ly;
use App\Common\Responses;
use Illuminate\Http\Request;
class MortgageController
{
    function debx(Request $request)
    {
        $params = $request->post();
        $dkm   = $params['dkm']; //贷款月数，20年就是240个月
        $dkTotal = $params['dkTotal']; //贷款总额
        $dknl  = $params['dknl']; //贷款年利率
        $emTotal = $dkTotal * $dknl / 12 * pow(1 + $dknl / 12, $dkm) / (pow(1 + $dknl / 12, $dkm) - 1); //每月还款金额
        $lxTotal = 0; //总利息
        for ($i = 0; $i < $dkm; $i++) {
            $lx   = $dkTotal * $dknl / 12;  //每月还款利息
            $em   = $emTotal - $lx; //每月还款本金
            $dkTotal = $dkTotal - $em;
            $lxTotal = $lxTotal + $lx;
            $data[$i]=[
                'em'=>$em,
                'lx'=>$lx,
                'emTotal'=>$emTotal,
                'lxTotal'=>$lxTotal,
                'how'=>$i+1
            ];
        }
        return Responses::success($data,200,'计算完成');
    }
}

